package com.tiance.demo.service.mysql.analyzer.pageindex;

import com.tiance.demo.service.mysql.utils.ByteUtils;
import com.tiance.demo.service.mysql.bo.pageindex.Infimum;
import com.tiance.demo.service.mysql.bo.pageindex.RecordHead;

public class InfimumAnalyzer {

    public static Infimum analyse(byte[] bytes) {
        Infimum infimum = new Infimum();
        infimum.setBytes(bytes);

        byte[] recordHeadBytes = new byte[RecordHead.SIZE];
        System.arraycopy(bytes, 0, recordHeadBytes, 0, RecordHead.SIZE);
        RecordHead recordHead = RecordHeadAnalyzer.analyse(recordHeadBytes);
        infimum.setRecordHead(recordHead);

        analyseMark(infimum);

        return infimum;
    }

    private static void analyseMark(Infimum infimum) {
        byte[] bytes = new byte[8];
        System.arraycopy(infimum.getBytes(), 5, bytes, 0, 8);

        String mark = ByteUtils.bytesToASCIIStr(bytes);
        infimum.setMark(mark);
    }
}
